﻿using System;
using System.Reflection;

public class StringValue : System.Attribute
{
    public StringValue(string value)
    {
        Value = value;
    }

    public string Value { get; private set; }
}

public static class StringEnum
{
    public static string GetStringValue(this Enum value)
    {
        string output = null;
        Type type = value.GetType();

        //Check first in our cached results...
        //Look for our 'StringValue'
        //in the field's custom attributes

        FieldInfo fi = type.GetField(value.ToString());
        var attrs =
            fi.GetCustomAttributes(typeof(StringValue),
                                   false) as StringValue[];
        if (attrs != null && attrs.Length > 0)
        {
            output = attrs[0].Value;
        }

        return output;
    }
}